package com.puman.dao.impl;

import java.util.List;
import java.util.Map;

import org.hibernate.criterion.DetachedCriteria;
import org.springframework.stereotype.Repository;

import com.core.BaseDaoImpl;
import com.core.Pager;
import com.puman.bean.Contract;
import com.puman.dao.ContractDao;

@Repository("contractDao")
public class ContractDaoImpl extends BaseDaoImpl<Contract> implements ContractDao {

	@Override
	public List<Contract> getList(Integer supplier_id) {
		String sql = "select c.id,c.supplier_id,s.name as SUPPLIER_NAME,c.gasstation_id,g.name as GASSTATION_NAME,c.company_id," +
				"cp.name as COMPANY_NAME,c.pay_way,c.descs,c.available_balance,c.contract_url,c.contract_signtime," +
				"c.contract_limittime,c.contract_startdate,c.contract_enddate,c.status,c.create_date,c.create_user_id," +
				"c.create_user_name,c.modify_date,c.modify_user_id,c.modify_user_name " +
				"from m_contract c " +
				"left join m_supplier s on c.supplier_id = s.id " +
				"left join m_gasstation g on c.gasstation_id = g.id " +
				"left join m_company cp on c.company_id = cp.id " +
				"where c.supplier_id = " + supplier_id +" order by c.modify_date desc";
		List<Contract> list = getSession().createSQLQuery(sql).addEntity(Contract.class).list();
		return list;
	}

	@Override
	public List<Contract> getListLike(Integer supplier_id, String name) {
		String sql = "select c.id,c.supplier_id,s.name as SUPPLIER_NAME,c.gasstation_id,g.name as GASSTATION_NAME,c.company_id," +
				"cp.name as COMPANY_NAME,c.pay_way,c.descs,c.available_balance,c.contract_url,c.contract_signtime," +
				"c.contract_limittime,c.contract_startdate,c.contract_enddate,c.status,c.create_date,c.create_user_id," +
				"c.create_user_name,c.modify_date,c.modify_user_id,c.modify_user_name " +
				"from m_contract c " +
				"left join m_supplier s on c.supplier_id = s.id " +
				"left join m_gasstation g on c.gasstation_id = g.id " +
				"left join m_company cp on c.company_id = cp.id and cp.name like '%"+name+"%'" +
				"where c.supplier_id = " + supplier_id +" order by c.modify_date desc";
		List<Contract> list = getSession().createSQLQuery(sql).addEntity(Contract.class).list();
		return list;
	}

}
